package com.hyperf.core.bean.criteria;

import com.alibaba.fastjson.JSON;
import com.hyperf.core.bean.criteria.annotation.Condition;
import com.hyperf.core.bean.criteria.annotation.Order;
import com.hyperf.core.bean.criteria.annotation.OrderEnum;
import com.hyperf.core.bean.criteria.annotation.SqlExpressionEnum;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

/**
 * @author lizhaoyang
 */
@Getter
@Setter
@NoArgsConstructor
public abstract class AbstractCriteria implements Serializable {

    private static final long serialVersionUID = -8253805167192718493L;

    /**
     * 分页查询参数
     * 页码
     */
    protected Integer page;

    /**
     * 分页查询参数
     * 每页数量
     */
    private Integer pageSize;

    /**
     * 是否查询软删的数据
     * 当值为null忽略该字段
     * 当值为true是使用isNotNull查询
     * 当值为false时使用isNull查询
     */
    @Condition(value = "deleted_at", sqlExpression = SqlExpressionEnum.SOFT_DELETE)
    protected Boolean queryDeleted = false;

    /**
     * 默认排序条件
     */
    @Order(value = "created_at", order = OrderEnum.DESC)
    protected String defaultOrder;

    @Override
    public String toString() {
        return JSON.toJSONString(this);
    }
}
